namespace EyeOpen.EasyEntityFramework.Data
{
	using System.Data.Common;
	using System.Data.Entity;
	using System.Data.Entity.ModelConfiguration.Conventions;

	using EyeOpen.EasyEntityFramework.Domain;

	public class AccountingContext 
		: DbContext
	{
		public AccountingContext(string providerName, string connectionString)
			: base(GetConnection(providerName, connectionString), true)
		{
		}

		public DbSet<Customer> CustomerSet
		{
			get
			{
				return Set<Customer>();
			}
		}

		protected override void OnModelCreating(DbModelBuilder modelBuilder)
		{
			modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
		}

		private static DbConnection GetConnection(string providerName, string connectionString)
		{
			var provider = DbProviderFactories.GetFactory(providerName);

			var connection = provider.CreateConnection();

			connection.ConnectionString = connectionString;

			return connection;
		}
	}
}